<h1>Seite erstellen</h1>
<?PHP
  if(!$_POST['alias']){
    $template = new Template();
	$template->load("site_new");
	$template->assign_var("URL","/admin/index.php?page=site-new&dir=".$_GET['dir']);
    $types = Page::getPagesTypes();
    if($types){
      foreach($types as $type){
        $index = $template->add_loop_item("TYPES");
        $template->assign_loop_var("TYPES",$index,"CLASS",$type->class);
        $template->assign_loop_var("TYPES",$index,"NAME",$type->name);
      }
    }
	$template->output();
  }
  else{
   if($_GET['dir']){
     $dir = $db->EscapeString($_GET['dir'])."/";
   }
   else{
     $dir = "";
   }
   $id = Page::create("../",$dir.$db->EscapeString($_POST['alias']),$db->EscapeString($_POST['type']));
   if($id){
     $template = new Template();
	 $template->load("site_new_succeeded");
	 $template->assign_var("URL","/admin/index.php");
	 $template->assign_var("ALIAS",$_POST['alias']);
	 $template->output();
   }
   else{
     $template = new Template();
	 $template->load("message");
	 $template->assign_var("MESSAGE","Die Seite konnte leider nicht erstellt werden.");
	 $template->output();
    }
  }
?>